#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

import os
import shutil
import datetime

timestamp = datetime.datetime.strftime(datetime.datetime.now(), '%c')


def doRuleForm(col):
    cname = col['cname']
    cinfo = col['cinfo']
    tp = '''
            {}: "",
    '''
    return tp.format(cname, cinfo)


def doRule(col):
    cname = col['cname']
    cinfo = col['cinfo']
    tp = '''
        {}: [
          // {{ required: true, message: "不能为空", trigger: "blur" }}
        ],
    '''
    return tp.format(cname, cinfo)


def doFormCol(col):
    cname = col['cname']
    cinfo = col['cinfo']
    tp = '''
          <el-col :sm="12">
            <el-form-item prop="{0}" label="{1}">
              <el-input
                maxlength="30"
                style="width: 300px"
                v-model.trim="ruleForm.{0}"
              ></el-input>
            </el-form-item>
          </el-col>
    '''
    return tp.format(cname, cinfo)


def toForm(item):
    with open('./input/form.vue') as f:
        tp = f.read()

        tnameLow = item['tname'].lower()
        cols = item['cols']

        formCol = ("\n").join([doFormCol(item) for item in cols])
        # print(formCol)

        ruleForm = ("\n").join([doRuleForm(item) for item in cols])
        # print(ruleForm)

        rule = ("\n").join([doRule(item) for item in cols])
        # print(rule)

        txt = tp.replace('#ruleForm#', ruleForm).replace('#rule#', rule).replace(
            '{tnameLow}', tnameLow).replace('{timestamp}', timestamp).replace('{formCol}', formCol)
        # print(txt)

        print('###', tnameLow, r'./output/{0}/{0}Form.vue'.format(tnameLow))
        print("\n")
        with open(r'./output/llbb/{0}/{0}Form.vue'.format(tnameLow), 'w') as fi:
            fi.write(txt)


def main():
    pass


if __name__ == '__main__':

    print('----success')
